package app.esb.common;

import cn.lily.com.configure.util.ESBSetting;
import cn.lily.com.db.DBFactory;
import cn.lily.com.db.sql.DBManager;
import cn.lily.com.db.sql.manager.DBOfflineManager;
import cn.lily.com.db.sql.manager.DBOwnerManager;
import cn.lily.com.enviroment.Enviroment;

/**
 * 数据库执行控制类
 * @author JiaJ
 *
 */
public class DBExcutor {
	
	/**
	 * 开启控制
	 */
	public static void beginTrans(){
		DBFactory.getActionDB().beginTransaction();
		DBOwnerManager.getDBManager().beginTransaction();
	}
	
	/**
	 * 提交
	 */
	public static void commit(){
		DBFactory.getActionDB().commit();
		DBOwnerManager.getDBManager().commit();
	}
	
	/**
	 * 回滚
	 */
	public static void rollback(){
		DBFactory.getActionDB().rollback();
		DBOwnerManager.getDBManager().rollback();
	}
	
	/**
	 * 释放
	 */
	public static void free(){
		DBFactory.getActionDB().free();
	}
	
	public static DBManager getDBManager(){
		if(ESBSetting.getBoolean("isOnline")){
			return DBOwnerManager.getDBManager();
		}else{
			return DBOfflineManager.getDBManager();
		}
	}
	
	public static void createEnv(){
		Enviroment.createEnv();
		Enviroment.getEnv().getLogBean().beginLog();
	}
	
}
